package com.pinganfu.mock.control;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.pinganfu.mock.model.AsynchronousMouldEntity;
import com.pinganfu.mock.model.ScoketMouldEntity;
import com.pinganfu.mock.service.IScoketMouldService;

@Controller
@RequestMapping(value = "/ScoketMould", produces = { "application/json;charset=UTF-8"})
public class ScoketMouldControl {
	
	@Resource
	private IScoketMouldService iScoketMouldService;
	
	@RequestMapping(value="/getScoketMouldList",method = { RequestMethod.GET, RequestMethod.POST })
	public @ResponseBody String getScoketMouldList(){
		
		List<ScoketMouldEntity> entities  =   iScoketMouldService.getScoketMouldList();
		
		AbsJsonObject json = new AbsJsonObject(AbsJsonObject.SUCCESS_OK);
   		json.addMessage("scoketMouldList", entities);
   		return json.messageToJsonString();
	}
	
	
	@RequestMapping(value="/getScoketMouldById",method = { RequestMethod.GET, RequestMethod.POST })
	public @ResponseBody String getScoketMouldById(@RequestParam Integer id){
		
		ScoketMouldEntity entity = new ScoketMouldEntity();
		
		entity.setId(id);
		
		List<ScoketMouldEntity> entities  =   iScoketMouldService.getScoketMouldById(entity);
		
		AbsJsonObject json = new AbsJsonObject(AbsJsonObject.SUCCESS_OK);
   		json.addMessage("scoketMouldList", entities);
   		return json.messageToJsonString();
	}
	
	
	@RequestMapping(value="/getScoketMouldListByport",method = { RequestMethod.GET, RequestMethod.POST })
	public @ResponseBody String getScoketMouldListByport(@RequestParam String port){
		
		ScoketMouldEntity entity = new ScoketMouldEntity();
		
		entity.setPort(port);
		
		List<ScoketMouldEntity> entities  =   iScoketMouldService.getScoketMouldListByport(entity);
		
		AbsJsonObject json = new AbsJsonObject(AbsJsonObject.SUCCESS_OK);
   		json.addMessage("scoketMouldList", entities);
   		return json.messageToJsonString();
	}
	
	
	@RequestMapping(value="/getScoketMouldByName",method = { RequestMethod.GET, RequestMethod.POST })
	public @ResponseBody String getScoketMouldByName(@RequestParam String url,@RequestParam String port){
		
		ScoketMouldEntity entity = new ScoketMouldEntity();
		
		entity.setUrl(url);
		entity.setPort(port);
		
		String entities  =  iScoketMouldService.getScoketMouldByName(entity);
		
		AbsJsonObject json = new AbsJsonObject(AbsJsonObject.SUCCESS_OK);
   		json.addMessage("scoketMouldList", entities);
   		return json.messageToJsonString();
	}
	
	
	@RequestMapping(value="/insertScoketMould",method = { RequestMethod.GET, RequestMethod.POST })
	public @ResponseBody String insertScoketMould(
			@RequestParam String serverName,
			@RequestParam String url,
			@RequestParam String port,
			@RequestParam String mould
			){
		ScoketMouldEntity entity = new ScoketMouldEntity();
		entity.setServerName(serverName);
		entity.setUrl(url);
		entity.setPort(port);
		entity.setMould(mould);
		entity.setCreateTime(new Date());
		
		Integer id = iScoketMouldService.insertScoketMould(entity);
		
		
		AbsJsonObject json = new AbsJsonObject(AbsJsonObject.SUCCESS_OK);
   		json.addMessage("insertScoketMould", id);
   		return json.messageToJsonString();
	}
	
	@RequestMapping(value="/updateScoketMould",method = { RequestMethod.GET, RequestMethod.POST })
	public @ResponseBody String updateScoketMould(
			@RequestParam Integer id,
			@RequestParam String serverName,
			@RequestParam String url,
			@RequestParam String port,
			@RequestParam String mould
			){
		ScoketMouldEntity entity = new ScoketMouldEntity();
		entity.setId(id);
		entity.setServerName(serverName);
		entity.setUrl(url);
		entity.setPort(port);
		entity.setMould(mould);
		entity.setCreateTime(new Date());
		
		iScoketMouldService.updateScoketMould(entity);
		
		
		AbsJsonObject json = new AbsJsonObject(AbsJsonObject.SUCCESS_OK);
   		json.addMessage("updateScoketMould", id);
   		return json.messageToJsonString();
	}
	
	
	@RequestMapping(value="/delScoketMould",method = { RequestMethod.GET, RequestMethod.POST })
	public @ResponseBody String delScoketMould(
			@RequestParam Integer id
			){
		ScoketMouldEntity entity = new ScoketMouldEntity();
		entity.setId(id);
		
		iScoketMouldService.delScoketMould(entity);
		
		AbsJsonObject json = new AbsJsonObject(AbsJsonObject.SUCCESS_OK);
   		json.addMessage("delScoketMould", entity.getId());
   		return json.messageToJsonString();
	}
	
}
